<?php

namespace plugin\ycMassage\app\model;

use plugin\ycMassage\utils\enum\Gender;

class MassageUserTechnician extends Model
{
    protected $pk = 'uid';
    public function getAgeAttr($value)
    {
        $time = time();
        $age = strtotime($value);
        return floor(($time - $age) / 31536000);
    }
    public function setAgeAttr($value)
    {
        $time = time();
        return date('Y-m-d', $time - $value * 31536000);
    }
    public function getWorkMeetAttr($value)
    {
        $time = time();
        $work_meet = strtotime($value);
        return floor(($time - $work_meet) / 31536000);
    }
    public function setWorkMeetAttr($value)
    {
        $time = time();
        return date('Y-m-d', $time - $value * 31536000);
    }
    public static function onAfterRead($model)
    {
        if ($model->gender) {
            $model->gender_text = Gender::getText($model->gender)['text'];
        }
        if($model->age){
            $year=date('Y')-$model->age;
            $year_remainder=$year%10;
            $integer_year=$year-$year_remainder;
            if($integer_year>=2000){
                $model->age_tag=str_pad($integer_year-2000,2,'0').'后';
            }else{
                $model->age_tag=($integer_year-1900).'后';
            }
        }
    }
}
